package com.wxxymakers.cklabrecruit.mapper;

import com.wxxymakers.cklabrecruit.entity.RegisterInfo;
import com.wxxymakers.cklabrecruit.entity.RegisterInfoExample;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

public interface RegisterInfoMapper {

    RegisterInfo getById(int id);

    @Select({
            "select left(datetime,4) from register_info",
            "group by left(datetime,4)",
            "order by datetime asc"
    })
    @ResultType(String.class)
    Set<String> getYears();

    @Update({"update register_info set status = status - 1 ",
            "where id = #{id} and ",
            "status > 0 and status <= 3"})
    @ResultType(Integer.class)
    int inject(@Param("id") Integer id);

    @Update({"update register_info set status = status + 1 ",
            "where id = #{id} and ",
            "status >= 0 and status < 3"})
    @ResultType(Integer.class)
    int pass(@Param("id") Integer id);

    ///////////////////
    long countByExample(RegisterInfoExample example);

    int deleteByExample(RegisterInfoExample example);

    @Delete({
        "delete from register_info",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into register_info (name, group_, ",
        "status, sex, stu_id, ",
        "grade, qq, tel, ",
        "email, datetime, ",
        "intro)",
        "values (#{name,jdbcType=VARCHAR}, #{group,jdbcType=VARCHAR}, ",
        "#{status,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR}, #{stuId,jdbcType=VARCHAR}, ",
        "#{grade,jdbcType=VARCHAR}, #{qq,jdbcType=VARCHAR}, #{tel,jdbcType=VARCHAR}, ",
        "#{email,jdbcType=VARCHAR}, #{datetime,jdbcType=TIMESTAMP}, ",
        "#{intro,jdbcType=LONGVARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(RegisterInfo record);

    int insertSelective(RegisterInfo record);

    List<RegisterInfo> selectByExampleWithBLOBs(RegisterInfoExample example);

    List<RegisterInfo> selectByExample(RegisterInfoExample example);

    @Select({
        "select",
        "Id, name, group_, status, sex, stu_id, grade, qq, tel, email, datetime, intro",
        "from register_info",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("com.wxxymakers.cklabrecruit.mapper.RegisterInfoMapper.ResultMapWithBLOBs")
    RegisterInfo selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") RegisterInfo record, @Param("example") RegisterInfoExample example);

    int updateByExampleWithBLOBs(@Param("record") RegisterInfo record, @Param("example") RegisterInfoExample example);

    int updateByExample(@Param("record") RegisterInfo record, @Param("example") RegisterInfoExample example);

    int updateByPrimaryKeySelective(RegisterInfo record);

    @Update({
        "update register_info",
        "set name = #{name,jdbcType=VARCHAR},",
          "group_ = #{group,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=VARCHAR},",
          "sex = #{sex,jdbcType=VARCHAR},",
          "stu_id = #{stuId,jdbcType=VARCHAR},",
          "grade = #{grade,jdbcType=VARCHAR},",
          "qq = #{qq,jdbcType=VARCHAR},",
          "tel = #{tel,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "datetime = #{datetime,jdbcType=TIMESTAMP},",
          "intro = #{intro,jdbcType=LONGVARCHAR}",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(RegisterInfo record);

    @Update({
        "update register_info",
        "set name = #{name,jdbcType=VARCHAR},",
          "group_ = #{group,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=VARCHAR},",
          "sex = #{sex,jdbcType=VARCHAR},",
          "stu_id = #{stuId,jdbcType=VARCHAR},",
          "grade = #{grade,jdbcType=VARCHAR},",
          "qq = #{qq,jdbcType=VARCHAR},",
          "tel = #{tel,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "datetime = #{datetime,jdbcType=TIMESTAMP}",
        "where Id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(RegisterInfo record);
}